/**
 * Copyright (c) 2018-2022, NXOS Development Team
 * SPDX-License-Identifier: Apache-2.0
 * 
 * Contains: Hook system
 * 
 * Change Logs:
 * Date           Author            Notes
 * 2022-10-10     JasonHu           Init
 */

#ifndef __NXOS_HOOKS_H__
#define __NXOS_HOOKS_H__

#include <nxos_mini.h>
#include <base/thread.h>
#include <base/syscall.h>

#ifdef CONFIG_NX_MAIN_THREAD_HOOK
void NX_MainThreadHook(void);
#define NX_MAIN_THREAD_HOOK() NX_MainThreadHook()
#else
#define NX_MAIN_THREAD_HOOK()
#endif

#ifdef CONFIG_NX_STARTUP_HOOK
void NX_StartupHook(void);
#define NX_STARTUP_HOOK() NX_StartupHook()
#else
#define NX_STARTUP_HOOK()
#endif

#ifdef CONFIG_NX_CORE_STARTUP_HOOK
void NX_CoreStartupHook(NX_UArch coreId);
#define NX_CORE_STARTUP_HOOK(coreID) NX_CoreStartupHook(coreID)
#else
#define NX_CORE_STARTUP_HOOK(coreID)
#endif

#ifdef CONFIG_NX_TICKS_HOOK
void NX_TicksHook(void);
#define NX_TICKS_HOOK() NX_TicksHook()
#else
#define NX_TICKS_HOOK()
#endif

#ifdef CONFIG_NX_IDLE_HOOK
void NX_IdleHook(void);
#define NX_IDLE_HOOK() NX_IdleHook()
#else
#define NX_IDLE_HOOK()
#endif

#ifdef CONFIG_NX_CONTEXT_SWITCH_HOOK
void NX_ContextSwitchHook(NX_Thread * prev, NX_Thread * next);
#define NX_CONTEXT_SWITCH_HOOK(prev, next) NX_ContextSwitchHook(prev, next)
#else
#define NX_CONTEXT_SWITCH_HOOK(prev, next)
#endif

#ifdef CONFIG_NX_PREV_THREAD_HOOK
void NX_PrevThreadHook(NX_Thread * thread);
#define NX_PREV_THREAD_HOOK(thread) NX_PrevThreadHook(thread)
#else
#define NX_PREV_THREAD_HOOK(thread)
#endif

#ifdef CONFIG_NX_POST_THREAD_HOOK
void NX_PostThreadHook(NX_Thread * thread);
#define NX_POST_THREAD_HOOK(thread) NX_PostThreadHook(thread)
#else
#define NX_POST_THREAD_HOOK(thread)
#endif

#ifdef CONFIG_NX_SYSCALL_ENTER_HOOK
void NX_SyscallEnterHook(NX_SyscallApi api, NX_UArch arg0, NX_UArch arg1, NX_UArch arg2,
        NX_UArch arg3, NX_UArch arg4, NX_UArch arg5, NX_UArch arg6);
#define NX_SYSCALL_ENTER_HOOK(api, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \
        NX_SyscallEnterHook(api, arg0, arg1, arg2, arg3, arg4, arg5, arg6)
#else
#define NX_SYSCALL_ENTER_HOOK(api, arg0, arg1, arg2, arg3, arg4, arg5, arg6)
#endif

#ifdef CONFIG_NX_SYSCALL_LEAVE_HOOK
void NX_SyscallLeaveHook(NX_SyscallApi api, NX_UArch retval);
#define NX_SYSCALL_LEAVE_HOOK(api, retval) NX_SyscallLeaveHook(api, retval)
#else
#define NX_SYSCALL_LEAVE_HOOK(api, retval)
#endif

#endif /* __NXOS_HOOKS_H__ */
